<script setup>
import {ref} from "vue";
import {ChineseDateUtil, DateTime} from "baitu";
import {Message} from 'view-ui-plus'

defineOptions({name: 'ChineseToDate'})

const remark = "仅支持 1900.1.31~2100.12.1"
const dateTime = ref()
const value = ref()

function generate() {
  const dateTimez = new DateTime(dateTime.value)
  if (dateTimez.getTime() >= new Date(2100, 11, 1).getTime() || dateTimez.getTime() <= new Date(1900, 1, 31).getTime()) {
    Message.error('选择的日期不在适用范围内')
    return
  }
  value.value = new DateTime(ChineseDateUtil.lunar2solar(dateTimez.getFullYear(), dateTimez.getMonth() + 1, dateTimez.getDate())).formatDate()
}
</script>

<template>
  <tool-page title="农历转公历" :value="value" @generate="generate" :remark="remark">
    <template #operate>
      <DatePicker v-model="dateTime" type="date" split-panels placeholder="请选择农历日期"
                  style="width: 180px; margin-right: 10px"></DatePicker>
    </template>
    <template #buttonBefore>

    </template>
  </tool-page>
</template>

<style scoped lang="scss">

</style>
